package invest.data;

import invest.pojo.datapojo.KlineHistory;
import invest.pojo.datapojo.Stock;
import lombok.SneakyThrows;

import java.util.List;

import static invest.data.HKtest.stockset;

public class Exe extends Thread{

    private Stock s;

    public Exe(Stock s) {
        this.s = s;
    }

    @SneakyThrows
    @Override
    public void run() {
        Stock stock = s;
        String code = stock.getSymbol();
        DataFactory dataFactory1 = new DataFactory(code);
        List<KlineHistory> klineHistories = (List<KlineHistory>) dataFactory1.getData(DataEnum.HKUSSTOCKKLINE);
        if (klineHistories.size() >= 4) {
            Double todayRiseRange = (klineHistories.get(0).getOpen() - klineHistories.get(1).getClose()) / klineHistories.get(1).getClose();
            Double yesterDayRiseRange = (klineHistories.get(1).getOpen() - klineHistories.get(2).getClose()) / klineHistories.get(2).getClose();
            Double yesterDayChangeRate = klineHistories.get(1).getTurnoverrate();
            if (yesterDayChangeRate != null) {
                Double yesterDaydiffer = klineHistories.get(1).getClose() - klineHistories.get(1).getOpen();
                boolean dayu = (todayRiseRange - yesterDayRiseRange) > 0;
                boolean yang = yesterDaydiffer > 0;
                boolean change = yesterDayChangeRate > 3;
                if (dayu && yang) {
                    stockset.add(stock);
                }
            }
        }
    }
}
